#include <bits/stdc++.h>

using namespace std;
const int N = 1e6 + 10;
struct lqq{
	int id;
	string s;
	bool friend operator <(lqq x, lqq y) {
		 for (int i = 0; i < (int)x.s.length(); i ++) {
		 	if(x.s[i] != y.s[i]) {
			 	if(i & 1) return x.s[i] > y.s[i];
			 	else return x.s[i] < y.s[i];
			 }
		 }
	}
}a[N];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t, n;
	cin >> t >> n;
	for (int i = 1; i <= t; i++) {
		cin >> a[i].s;
		a[i].id = i;
	}
	sort(a + 1, a + t + 1);
	for (int i = 1; i <= t; i++)cout << a[i].id << " ";
}
